package com.oliet.common.vo.user;

import cn.hutool.core.collection.CollectionUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.collect.Lists;
import com.oliet.entity.Users;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author jiaZhenpeng
 * @Title: UserVO
 * @Package com.oliet.common.vo
 * @Description: 用户返回数据
 * @date 2023-12-03 10:28
 */
@Data
public class UserVO {

    /**
     * 用户id
     */
    private Long id;

    /**
     * 用户编码
     */
    private String code;

    /**
     * 用户名
     */
    private String username;

    /**
     * 姓名
     */
    private String fullName;

    /**
     * 邮箱地址
     */
    private String email;

    /**
     * 手机号
     */
    private String mobileNumber;

    /**
     * 是否是超级管理员
     */
    private Boolean isSuperAdmin;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date dateCreated;

    /**
     * 可用IP
     */
    private String availableIp;

    /**
     * 角色数据
     */
    private List<Long> roleIds;

    public static List<UserVO> poListConverVoList(List<Users> poList, Map<Long, List<Long>> roleIdMap) {
        List<UserVO> result = Lists.newArrayList();
        if (CollectionUtil.isEmpty(poList)){
            return result;
        }
        result = poList.stream().map(po->{
            UserVO vo = new UserVO();
            BeanUtils.copyProperties(po, vo);
            vo.setRoleIds(roleIdMap.get(vo.getId()));
            return vo;
        }).collect(Collectors.toList());
        return result;
    }
}
